package cn.zhiquxing.service;


import cn.zhiquxing.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

@Repository
public class UserRepositoryImpl {
    
    @Autowired
    private MongoTemplate mongoTemplate;
    
    public User findUerByIdOrUserName(Long id, String userName) {
        Criteria idCriteria = Criteria.where("id").is(id).and("userName");
        Criteria userNameCriteria = Criteria.where("userName").is(userName);
        Criteria criteria = new Criteria();
        criteria.orOperator(idCriteria, userNameCriteria);
        Query query = Query.query(criteria);
        return mongoTemplate.findOne(query, User.class);
    }

}
